﻿using CommunicationClass.Client.Model;
using CommunicationClass.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static CommunicationClass.Model.SendReceiveEnum;

namespace CommunicationClass.Auxiliary
{
    /// <summary>
    /// 发送数据有黏贴数据 并发数据的静态处理类
    /// </summary>
    public static class SendLengthCalculation
    {
        /// <summary>
        /// 发送消息转换
        /// </summary>
        /// <param name="sendModel">发送的消息</param>
        /// <returns>byte[]</returns>
        public static byte[] SendJsonConvert(SendModel sendModel)
        {
            byte[] json = CommunicationClass.Auxiliary.JsonHelper.JsonDateSerializer<SendModel>(sendModel);
            int d = json.Length;
            string jsonlength = json.Length.ToString();
            int forjsonlength = jsonlength.Length;
            for (int i = 0; i < MessageSendConfigure.MaxMessageSendLength - forjsonlength; i++)
            {
                jsonlength = "0" + jsonlength;
            }
            byte[] sf = Encoding.Unicode.GetBytes(jsonlength);
            List<byte> list = json.ToList<byte>();
            for (int i = sf.Length-1; i >= 0; i--)
            {
                list.Insert(0, sf[i]);

            }
            return list.ToArray<byte>(); ;
        }



    }
}
